package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.PersonInfo;
import com.noahplat.person.service.PersonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: PersonInfoController
 * @Description: 人员详细资料controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/personInfo")
@Validated
public class PersonInfoController {

    @Autowired
    private PersonInfoService personInfoService;

    /**
     * 获取人员详细资料
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonInfoController:getPersonInfo')")
    @GetMapping("/getPersonInfo")
    public Result getPersonInfo(@NotNull(message = "人员ID不能为空 ") @Min(value = 1, message = "人员ID不合法") Long pid){
        return personInfoService.getPersonInfo(pid);
    }

    /**
     * 更新人员详细资料
     * @param personInfo
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonInfoController:updatePersonInfo')")
    @PutMapping("/updatePersonInfo")
    public Result updatePersonInfo(@RequestBody PersonInfo personInfo){
        return personInfoService.updatePersonInfo(personInfo);
    }

    /**
     * 条件查询人员资料
     * @param acctid
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonInfoController:getPersonInfos')")
    @GetMapping("/getPersonInfos")
    public Result getPersonInfos(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit,@NotNull(message = "账套ID不能为空 ") @Min(value = 1, message = "账套ID不合法") Long acctid,String name){
        return personInfoService.getPersonInfos(page,limit,acctid,name);
    }

    /**
     * 条件查询人员健康数据
     * @param page
     * @param limit
     * @param acctid
     * @param name
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:PersonInfoController:getHealths')")
    @GetMapping("/getHealths")
    public Result getHealths(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit,@NotNull(message = "账套ID不能为空 ") @Min(value = 1, message = "账套ID不合法")Long acctid,String name){
        return personInfoService.getHealths(page, limit, acctid, name);
    }

}
